import { API_LIST } from '../../../Api/Api'
import { commonTableList, BuiltInData } from '../Common/common'
import {
    SelectButton,
    DelDataButton,
    ExamineFillButton,
    MonitorVideoButton,
    ExecuteButton,
    SelectExcelButton,
} from '../Common/options'
import { LabHandleType, ProjectList } from '../Common/Conversion'

export const LabDuctility = async ({ url, OptionsEvent, ClientData, Permission, actionRef }) => {
    const { hostname } = window.location
    const labHandleType = await LabHandleType()
    let data = {
        pageSize: 10,
        get: API_LIST()[`get${url}OC`],
        added: `pos${url}`,
        modify: `put${url}`,
        delete: `del${url}`,
        params: { pageIndex: 1, OGroupId: 'asc@-10', OTestFr: 'asc@-9' },
        options: [
            <SelectExcelButton
                key="excel"
                title="下载Excel"
                OptionsEvent={OptionsEvent}
                api={API_LIST()['getLabDuctilityExcel']}
            />,
        ],
        columns: [
            commonTableList.uuid,
            { ...commonTableList.SearchSort, selectType: 'LabDuctility' },
            {
                ...commonTableList.projectUuid,
                valueEnum: await ProjectList(),
                hideInAdded: true,
                hideInModify: true,
                hideInTable: true,
                hideInSearch: !hostname.includes('jszx'),
            },
            { ...commonTableList.organizationUuid, valueEnum: ClientData.organization },
            {
                dataIndex: 'ownerOrganizationName',
                title: '样品来源',
                valueType: 'input',
                width: 150,
            },
            {
                dataIndex: 'taskNo',
                title: '任务编号',
                valueType: 'input',
                width: 250,
            },
            {
                dataIndex: 'testFr',
                title: '试件序号',
                valueType: 'input',
                hideInSearch: true,
                width: 250,
            },
            {
                dataIndex: 'sampleName',
                title: '样品名称',
                valueType: 'input',
                width: 250,
            },
            {
                dataIndex: 'startTime',
                title: '开始时间',
                valueType: 'input',
                width: 250,
                hideInSearch: true,
            },
            {
                dataIndex: 'endTime',
                title: '结束时间',
                valueType: 'input',
                width: 250,
                hideInSearch: true,
            },
            {
                dataIndex: 'testTemp',
                title: '试验温度',
                valueType: 'input',
                hideInSearch: true,
                width: 250,
            },
            {
                dataIndex: 'extensionSpeed',
                title: '延伸速度',
                valueType: 'input',
                hideInSearch: true,
                width: 250,
            },
            {
                dataIndex: 'ductility',
                title: '延伸值',
                valueType: 'input',
                hideInSearch: true,
                width: 250,
            },
            {
                dataIndex: 'averageDuctility',
                title: '平均延度',
                valueType: 'input',
                hideInSearch: true,
                width: 250,
            },
            {
                dataIndex: 'result',
                title: '评定结果',
                valueType: 'select',
                valueEnum: BuiltInData.result,
                width: 150,
            },
            {
                dataIndex: 'labHandleTypeUuid',
                title: '处理意见',
                valueType: 'select',
                ellipsis: true,
                valueEnum: labHandleType,
                width: 180,
            },
            {
                dataIndex: 'remark',
                title: '意见说明',
                valueType: 'input',
                hideInSearch: true,
                width: 180,
            },
            {
                dataIndex: 'handleUserName',
                title: '审核人',
                valueType: 'input',
                hideInSearch: true,
                width: 180,
            },
            {
                dataIndex: 'handleTime',
                title: '审核时间',
                valueType: 'input',
                hideInSearch: true,
                width: 180,
            },
            { ...commonTableList.isEnabled, rules: true, hideInSearch: false },
            {
                dataIndex: 'equipmentNumber',
                title: '设备编号',
                valueType: 'input',
                width: 250,
            },
            {
                dataIndex: 'equipmentName',
                title: '设备名称',
                valueType: 'input',
                width: 400,
            },
            commonTableList.BeginStatDate,
            commonTableList.EndStatDate,
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 400,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { originalDataTable, labHandleTypeUuid, isEnabled, groupId, endTime, startTime, testDate } =
                        record
                    return [
                        Permission.findIndex(v => v.uuid === '5f6622b1-466b-4db8-add8-0c766b01d0f8') !== -1 &&
                            !labHandleTypeUuid && (
                                <ExamineFillButton
                                    key="Examine"
                                    OptionsEvent={OptionsEvent}
                                    title="处理意见"
                                    data={{
                                        options: labHandleType,
                                        groupId: groupId,
                                        url: 'posLabDuctilityUpdateRemark',
                                        actionRef,
                                    }}
                                />
                            ),
                        ((endTime && startTime) || testDate) && (
                            <MonitorVideoButton
                                key="video"
                                title="监控画面"
                                OptionsEvent={OptionsEvent}
                                data={{
                                    url: 'getLabDataCameraByOriginalDataTable',
                                    originalDataTable,
                                    labHandleTypeUuid,
                                    startTime,
                                    endTime,
                                    testDate,
                                }}
                            />
                        ),
                        <SelectButton
                            key="select"
                            title="样品来源"
                            OptionsEvent={OptionsEvent}
                            data={{
                                actionRef,
                                options: ClientData.organization,
                                label: '样品来源',
                                url: 'posLabDuctilitySetOwner',
                                uuid: record.uuid,
                            }}
                        />,
                        Permission.findIndex(v => v.uuid === '302c5e62-4822-4ce3-a855-8636ebc88e66') !== -1 &&
                            isEnabled !== 1 && (
                                <ExecuteButton
                                    actionRef={actionRef}
                                    key="one"
                                    title="启用"
                                    url="posLabDuctilitySetIsEnabled"
                                    path={[groupId, 1]}
                                    tips="数据启用成功!"
                                />
                            ),

                        Permission.findIndex(v => v.uuid === '302c5e62-4822-4ce3-a855-8636ebc88e66') !== -1 &&
                            isEnabled === 1 && (
                                <ExecuteButton
                                    actionRef={actionRef}
                                    key="one"
                                    title="禁用"
                                    danger={true}
                                    url="posLabDuctilitySetIsEnabled"
                                    path={[groupId, 0]}
                                    tips="数据禁用成功!"
                                />
                            ),
                        Permission.findIndex(v => v.uuid === '3151537b-f570-48ca-b7ab-f839990810a4') !== -1 && (
                            <DelDataButton
                                OptionsEvent={OptionsEvent}
                                key="del"
                                title="删除"
                                url={url}
                                uuid={record.uuid}
                            />
                        ),
                    ]
                },
            },
        ],
    }
    return data
}
